package com.cmcc.pcap.packet.util.pfcpUtile;

import com.cmcc.packet.entity.PfcpEntity;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

public class CPFunctionFeaturesUtil implements PfcpTypeUtil{
    private static Logger logger = LogManager.getLogger(CPFunctionFeaturesUtil.class);
    int SupportedFeatures;

    @Override
    public PfcpEntity.InformationElement analysisIe(byte[] sub_payload) {
        PfcpEntity.InformationElement peie = new PfcpEntity.InformationElement();
        peie.setType(((sub_payload[0] & 0xff) << 8) + (sub_payload[1] & 0xff));
        peie.setLength(((sub_payload[2] & 0xff) << 8) + (sub_payload[3] & 0xff));
        Map<String, String> dataMap = new HashMap<>();
        dataMap.put("supported_features", String.valueOf(sub_payload[4] & 0xff));
        dataMap.put("load", String.valueOf((((sub_payload[4] >> 0) & 0x1) == 1)));
        dataMap.put("ovrl", String.valueOf((((sub_payload[4] >> 1) & 0x1) == 1)));
        dataMap.put("epfar", String.valueOf((((sub_payload[4] >> 2) & 0x1) == 1)));
        dataMap.put("sset", String.valueOf((((sub_payload[4] >> 3) & 0x1) == 1)));
        dataMap.put("budl", String.valueOf((((sub_payload[4] >> 4) & 0x1) == 1)));
        dataMap.put("mpas", String.valueOf((((sub_payload[4] >> 5) & 0x1) == 1)));
        dataMap.put("ardr", String.valueOf((((sub_payload[4] >> 6) & 0x1) == 1)));
        dataMap.put("uiaur", String.valueOf((((sub_payload[4] >> 7) & 0x1) == 1)));
        peie.setDataMap(dataMap);
        return peie;
    }
}
